﻿using System.Collections.Generic;

namespace Integrity
{
  public static class Integrity
  {
    private static class PerOwnerStorage<T>
    {
      public static readonly List<IProperty> Properties = new List<IProperty>();
    }

    internal static void Register<T>(IProperty prop)
      where T : class
    {
      PerOwnerStorage<T>.Properties.Add(prop);
    }
    public static List<IProperty> GetPropertiesByOwner<T>()
    {
      return PerOwnerStorage<T>.Properties;
    }
    public static void ResetAllPropertiesOf<T>(T owner)
    {
      foreach (var p in GetPropertiesByOwner<T>())
        p.Reset(owner);
    }

    public static void Release<T>(T owner)
    {
      ResetAllPropertiesOf(owner);
      var ifc = owner as IIntegrityObject;
      if (ifc != null)
        ifc.OnReleased();
    }
  }
}